//
//  MBProgressHUD+Add.m
//  视频客户端
//
//  Created by mj on 13-4-18.
//  Copyright (c) 2013年 itcast. All rights reserved.
//

#import "MBProgressHUD+Add.h"

@implementation MBProgressHUD (Add)

#pragma mark 显示信息
+ (void)show:(NSString *)text icon:(NSString *)icon view:(UIView *)view offset:(int)y
{
    [MBProgressHUD hideHUDForView:view animated:YES];
    
    if (view == nil) view = [UIApplication sharedApplication].keyWindow;
    // 快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.labelText = text;
    hud.yOffset = y;
    if (icon.length > 0) {
        // 设置图片
        hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"MBProgressHUD.bundle/%@", icon]]];
        // 再设置模式
        hud.mode = MBProgressHUDModeCustomView;
    } else {
        hud.mode = MBProgressHUDModeText;
    }
    
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    
    // 1秒之后再消失
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(kDELAY * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [MBProgressHUD hideHUDForView:view animated:YES];
    });
}

#pragma mark 显示错误信息
+ (void)showError:(NSString *)error toView:(UIView *)view offset:(int)y {
    [self show:error icon:@"error.png" view:view offset:y];
}

+ (void)showSuccess:(NSString *)success toView:(UIView *)view offset:(int)y
{
    [self show:success icon:@"success.png" view:view offset:y];
}

+ (void)showText:(NSString *)text toView:(UIView *)view offset:(int)y {
    
    [self show:text icon:@"" view:view offset:y];
}

#pragma mark 显示一些信息
+ (MBProgressHUD *)show:(NSString *)message toView:(UIView *)view offset:(int)y {
    [MBProgressHUD hideHUDForView:view animated:YES];
    
    if (view == nil) view = [UIApplication sharedApplication].keyWindow;
    // 快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.mode = MBProgressHUDModeIndeterminate;
    hud.labelText = message;
    hud.yOffset = y;
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    // YES代表需要蒙版效果
    hud.dimBackground = NO;
    return hud;
}
@end
